﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Agile.Engine.Utils;
using Fis.Win.Utils;

namespace Fis.Win.Forms
{
    public partial class EnterpriseViewForm : EditForm
    {
        public EnterpriseViewForm()
        {
            InitializeComponent();
        }

        public override void InitializeBinding()
        {
            var d = ViewModel["data"] as DataTable;

            Fis.Win.Utils.UIUtils.ClearBindings(dataLayoutControl1);
            Fis.Win.Utils.UIUtils.TagBindings(dataLayoutControl1, d);
        }


        public override void InitializeViewUI()
        {
            iSaveNew.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
        }

        private void EnterpriseViewForm_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“cacheDataSet.TBOOK”中。您可以根据需要移动或删除它。
            //this.tBOOKTableAdapter.Fill(this.cacheDataSet.TBOOK);

        }

        protected override bool ValidateBeforeSave()
        {
            if (FNUMBERTextEdit.Text.Length < 15 || FNUMBERTextEdit.Text.Length > 20)
            {
                MessageBox.Show("税务登记号长度必须在15-20位之间");
                return false;
            }

            if (FCONTACTTextEdit.Text.Length != 15)
            {
                MessageBox.Show("营业执照号长度必须是15位");
                return false;
            }

            return base.ValidateBeforeSave();
        }

        protected override bool SaveProcess()
        {
            ///失败
            if (!ViewProvider.ExecuteUpdate(ViewModel))
            {
                return false;
            }

            Message = "保存成功";
            AppSession.InitializeBookInfo();
            return true;
        }

    }
}
